﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.SalaryRules
{
    public partial class SalaryRulesViewInfo : SERP.Modules.ModuleBase
    {
        private SalaryRulesController controller = new SalaryRulesController();
        public SalaryRulesController Controller
        {
            get
            {
                return controller;
            }
        }
        DataTable tblCalculationType;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadLanguage();
            if (!this.IsPostBack)
            {
                BindInfo();
            }
        }
        //Load All lable text
        private void LoadLanguage()
        {
            labelRuleName.Text = SalaryRulesStringMapping.RuleName + ":";
            labelNote.Text = SalaryRulesStringMapping.Note + ":";
            labelStatus.Text = SalaryRulesStringMapping.Status + ":";
            labelFromDay.Text = SalaryRulesStringMapping.FromDay + ":";
            labelToDay.Text = SalaryRulesStringMapping.ToDay + ":";
            lblInfo.Text = Constants.APP_INFO + " " + SalaryRulesStringMapping.SalaryRules;
            lblItem.Text = Constants.APP_INFO + " " + SalaryRuleItemsStringMapping.SalaryRuleItems;

        }
        public string GetCalculationType(int calculationType)
        {
            return tblCalculationType.Select("ID=" + calculationType.ToString())[0]["Name"].ToString();
        }
        public string GetSalaryField(int salaryFieldId)
        {
            return SalaryFieldsController.GetSalaryFieldById(salaryFieldId).FieldName;
        }
        public SalaryRulesEntity GetObject()
        {
            controller.LoadObject(Int32.Parse(Request["SalaryRuleId"]));
            return controller.SalaryRulesObject;
        }
        private void BindInfo()
        {
            tblCalculationType = SalaryRulesController.GetCalculationTypesTable();
            SalaryRulesEntity o = GetObject();
            CopyToSreen(o);
            BindItems(o.SalaryRuleId);
        }
        private void BindItems(int salaryRuleId)
        {
            SalaryRuleItemsController controller = new SalaryRuleItemsController();
            controller.LoadAllDSSalaryRuleItems(salaryRuleId);
            gridData.DataSource = controller.Table;
            gridData.DataBind();
        }
        private void CopyToSreen(SalaryRulesEntity o)
        {
            txtRuleName.Text = o.RuleName;
            txtNote.Text = o.Note;
            txtStatus.Text = Convert.ToString(o.Status);
            txtFromDay.Text = Convert.ToString(o.FromDay);
            txtToDay.Text = Convert.ToString(o.ToDay);
        }
    }
}
